package cn.com.blueInfo.bpm.template.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.template.request.ViewDTO;
import cn.com.blueInfo.bpm.template.response.ViewVO;
import cn.com.blueInfo.bpm.template.service.ViewService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 流程图配置表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:41:15
 */
@Tag(name = "流程图配置 接口")
@RestController
@RequestMapping("/template/view")
public class ViewController extends BaseController {

    @Autowired
    private ViewService viewService;

    /**
     * 新建流程图配置
     * @param viewDTO 流程图配置参数
     * @return ResultInfo
     */
    @Operation(summary = "新增流程图配置")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createView(
            @Validated({Create.class, Default.class}) @RequestBody ViewDTO viewDTO) {
        return viewService.addView(viewDTO);
    }

    /**
     * 批量新建流程图配置
     * @param viewDTOList 流程图配置参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建流程图配置")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateView(
            @Validated({Create.class, Default.class}) @RequestBody List<ViewDTO> viewDTOList) {
        return viewService.batchAddView(viewDTOList);
    }

    /**
     * 根据ID删除流程图配置
     * @param viewId 流程图配置ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除流程图配置")
    @DeleteMapping("/removeInfo/{viewId}")
    public ResultInfo<Integer> deleteViewById(
            @Parameter(name = "ID") @PathVariable Long viewId) {
        return viewService.removeView(viewId);
    }

    /**
     * 批量根据ID删除流程图配置
     * @param viewIdList 流程图配置ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除流程图配置")
    @DeleteMapping("/removeInfoList/{viewIdList}")
    public ResultInfo<Integer> batchDeleteViewById(
            @Parameter(name = "ID") @PathVariable List<Long> viewIdList) {
        return viewService.batchRemoveView(viewIdList);
    }

    /**
     * 根据ID全量更新流程图配置
     * @param viewId 流程图配置ID
     * @param viewDTO 流程图配置参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新流程图配置")
    @PutMapping("/modifyInfo/{viewId}")
    public ResultInfo<Integer> updateViewFull(
            @Parameter(name = "ID") @PathVariable Long viewId,
            @Validated({Update.class, Default.class}) @RequestBody ViewDTO viewDTO) {
        validateUpdateId(viewId, viewDTO.getId());
        return viewService.modifyView(viewDTO);
    }

    /**
     * 根据ID部分更新流程图配置
     * @param viewId 流程图配置ID
     * @param viewUpdatePartialDTO 流程图配置参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新流程图配置")
    @PatchMapping("/modifyPartialInfo/{viewId}")
    public ResultInfo<Integer> updateViewPartial(
            @Parameter(name = "ID") @PathVariable Long viewId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            ViewDTO.UpdatePartialDTO viewUpdatePartialDTO) {
        validateUpdateId(viewId, viewUpdatePartialDTO.getId());
        return viewService.modifyViewPartial(viewUpdatePartialDTO);
    }

    /**
     * 根据ID查询流程图配置
     * @param viewId 流程图配置ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询流程图配置")
    @GetMapping("/getInfo/{viewId}")
    public ResultInfo<ViewVO> getViewById(
            @Parameter(name = "ID") @PathVariable Long viewId) {
        return viewService.queryViewById(viewId);
    }

    /**
     * 分页查询流程图配置
     * @param viewQueryDTO 流程图配置参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询流程图配置")
    @GetMapping("/getInfos")
    public ResultInfo<Page<ViewVO>> getViewPage(
            @Validated ViewDTO.QueryDTO viewQueryDTO) {
        return viewService.queryViewPage(viewQueryDTO);
    }

    /**
     * 根据条件查询流程图配置
     * @param viewQueryDTO 流程图配置参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询流程图配置")
    @GetMapping("/getInfoList")
    public ResultInfo<List<ViewVO>> getViewList(
            @Validated ViewDTO.QueryDTO viewQueryDTO) {
        return viewService.queryViewList(viewQueryDTO);
    }

}
